#
# @lc app=leetcode.cn id=1035 lang=python
#
# [1035] 不相交的线
#

# @lc code=start
class Solution(object):
    def maxUncrossedLines(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: int
        """
        dp = [0] * (len(nums2)+1)
        for i in range(len(nums1)):
            prev = 0
            for j in range(len(nums2)):
                cur = dp[j+1]
                if nums1[i] == nums2[j]:
                    dp[j+1] = prev + 1
                else:
                    dp[j+1] = max(dp[j], dp[j+1])
                prev = cur
        return dp[-1]
        
# @lc code=end

